<?php if (!defined("BASEPATH")) exit("No direct script access allowed"); ?>

<script type="text/javascript">
	Ext.onReady(function() {

		var Panel = new Ext.Panel({
			renderTo: 'form-password_change',
			border: false,
			layout: 'fit',
			items: [

				passwordChangeForm = new Ext.FormPanel({
					padding: 10,
					labelAlign: 'right',
					labelWidth: 110,
					autoHeight: true,
					autoWidth: true,
					border: false,
					defaultType: 'textfield',
					waitMsgTarget: true,
					items: [{
							xtype:'fieldset',
							title: '<?=$this->db->escape_str($this->lang->line("PASSWORD"))?>',
							autoHeight:true,
							layout: {
								type: 'anchor'
							},
							anchor:'50%',
							items: [
								new Ext.ux.PasswordMeter({
									xtype: 'textfield',
									id: 'password',
									inputType: 'password',
									fieldLabel: '<?=$this->db->escape_str($this->lang->line("PASSWORD"))?>',
									name: 'usr_password',
									maxLength: 255,
									maxLengthText: '<?=$this->db->escape_str($this->lang->line("YOU_HAVE_EXCEEDED_THE_MAXIMUM_LENGTH"))?>',
									allowBlank: true,
									anchor:'100%'
								})]
						},{
							xtype:'fieldset',
							title: '<?=$this->db->escape_str($this->lang->line("RE-TYPE_PASSWORD"))?>',
							autoHeight:true,
							layout: {
								type: 'anchor'
							},
							anchor:'50%',
							items: [{
								xtype: 'textfield',
								inputType: 'password',
								fieldLabel: '<?=$this->db->escape_str($this->lang->line("RE-TYPE_PASSWORD"))?>',
								name: 'usr_password_re',
								maxLength: 255,
								maxLengthText: '<?=$this->db->escape_str($this->lang->line("YOU_HAVE_EXCEEDED_THE_MAXIMUM_LENGTH"))?>',
								allowBlank: true,
								anchor:'100%'
							}]
						}
					]
				})

			],

			bbar: {
				items: [{
					text: '<?=$this->db->escape_str($this->lang->line("SAVE"))?>',
					handler: function() {
						if(!passwordChangeForm.getForm().isValid()) {
							Ext.Msg.show({
								title:'<?=$this->db->escape_str($this->lang->line("ERROR"))?>',
								msg: '<?=$this->db->escape_str($this->lang->line("PLEASE_CORRECT_THE_ERRORS"))?>!',
								buttons: Ext.Msg.OK,
								icon: Ext.MessageBox.WARNING
							});
						} else {
							if(passwordChangeForm.getForm().isDirty()) {
								passwordChangeForm.getForm().submit({
									url: '<?=site_url()?>admin/password_change_insert_update',
									success: function(form, resp){
										if(resp.result.error) {
											Ext.Msg.show({
												title:'<?=$this->db->escape_str($this->lang->line("ERROR"))?>',
												msg: resp.result.error,
												buttons: Ext.Msg.OK,
												icon: Ext.MessageBox.ERROR
											});
										} else {
											Ext.Msg.show({
												title:'<?=$this->db->escape_str($this->lang->line("PASSWORD_CHANGED"))?>',
												msg: '<?=$this->db->escape_str($this->lang->line("YOUR_PASSWORD_CHANGED_SUCCESSFULLY"))?>',
												buttons: Ext.Msg.OK,
												icon: Ext.MessageBox.INFO
											});
											passwordChangeForm.getForm().reset();
										}
									}
								});
							}
						}
					},
					icon: '<?=MEDIA?>icon/disk.png'
				}, {
					xtype: 'tbseparator'
				},{
					text: '<?=$this->db->escape_str($this->lang->line("CANCEL"))?>',
					handler: function() {
						passwordChangeForm.getForm().reset();
						Ext.getCmp('password').el.next().first().setWidth(0, true);
					}
				}],
				buttonAlign : 'right'
			}

		})

	})
</script>


<div id="form-password_change"></div>